home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\TERM.C < prev    next >
C/C++ Source or Header  |  1994-12-28  |  18KB  |  898 lines

  1. /*
  2.  * term.c: termcap stuff... 
  3.  *
  4.  * Written By Michael Sandrof
  5.  * HP-UX modifications by Mark T. Dame (Mark.Dame@uc.edu) 
  6.  * Termio modifications by Stellan Klebom (d88-skl@nada.kth.se) 
  7.  * Copyright(c) 1990 
  8.  * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 
  9.  *
  10.  * i want to clean this file up, but i can't be bothered.  anyone
  11.  * wanna do it for me ?
  12.  */
  13.  
  14. #ifndef lint
  15. static    char    rcsid[] = "@(#)$Id: term.c,v 1.32 1994/10/09 06:39:35 mrg Stab $";
  16. #endif
  17.  
  18. #include "irc.h"
  19.  
  20. #ifdef ESIX
  21. # include <lan/net_types.h>
  22. # include <lan/net_ioctl.h>
  23. # include <sgtty.h>
  24. # include <termio.h>
  25. #endif /* ESIX */
  26.  
  27. #ifdef XD88
  28. # include <sys/termios.h>
  29. #endif /* XD88 */
  30.  
  31. #ifdef SVR3
  32. # include <sys/stat.h>
  33. # include <sgtty.h>
  34. # include <sys/stream.h>
  35. # ifdef HAVE_SYS_PTEM_H
  36. #  include <sys/ptem.h>
  37. # endif
  38. # define CBREAK RAW
  39. # define USE_TERMIO /* bah */
  40. #endif /* SVR3 */
  41.  
  42. #ifdef SVR4
  43. # include <sys/stat.h>
  44. # include <termios.h>
  45. # include <sys/ttold.h>
  46. # include <sys/stream.h>
  47. # include <sys/ttcompat.h>
  48. # define CBREAK RAW
  49. # define USE_TERMIO
  50. #endif /* SVR4 */
  51.  
  52. #ifdef M_UNIX
  53. # include <sys/stat.h>
  54. # include <sys/stream.h>
  55. # include <sys/ptem.h>
  56. # include <termio.h>
  57. #endif /* M_UNIX */
  58.  
  59. #ifdef HPUX
  60. # define _TERMIOS_INCLUDED
  61. # define _INCLUDE_TERMIO
  62. # include <sys/termio.h>
  63. # define USE_TERMIO
  64. #endif /* HPUX */
  65.  
  66. #include <sys/ioctl.h>
  67. #include "term.h"
  68. #include "translat.h"
  69.  
  70. #ifdef ISC
  71. # include <sys/sioctl.h>
  72. # define USE_TERMIO
  73. #endif /* ISC22 */
  74.  
  75. #ifdef USE_TERMIO
  76. # include <sys/termio.h>
  77. #endif /* USE_TERMIO */
  78.  
  79. #ifdef ISC22
  80. # undef TIOCSETC
  81. # undef TIOCGETC
  82. #endif /* ISC22 */
  83.  
  84. #ifdef USING_CURSES
  85. # include <curses.h>
  86. #endif /* USING_CURSES */
  87.  
  88. #if defined(POSIX) && !defined(sun) && !defined(_IBMR2)
  89. # ifdef HAVE_SYS_TTOLD_H
  90. #  include <sys/ttold.h>
  91. # endif /* HAVE_SYS_TTOLD_H */
  92. #endif /* POSIX && !sun && !_IBMR2 */
  93.  
  94. #ifdef __linux__
  95. # define USE_TERMIO
  96. #endif
  97.  
  98. /*
  99.  * net/2 defined this as 0.5, and 4.4 as 1..
  100.  * i hope other systems based on this don't change it (netbsd,
  101.  * bsdi, freebsd ..)
  102.  */
  103. #ifdef BSD4_4
  104. # include <termios.h>
  105. # define termio termios
  106. # define USE_TERMIO
  107. #endif
  108.  
  109. #ifdef __QNX__
  110. # include <termios.h>
  111. # define termio termios
  112. # define USE_TERMIO
  113. # undef TIOCLSET
  114. # undef TCSETA
  115. # undef TCGETA
  116. #endif
  117.  
  118. /* Missing on ConvexOS, idea picked from SunOS */
  119. #if defined(__convex__) && !defined(LPASS8)
  120. # define LPASS8 (L004000>>16)
  121. #endif
  122.  
  123. #include "window.h"
  124. #include "screen.h"
  125.  
  126. #ifndef    STTY_ONLY
  127. extern    char    *tgetstr();
  128. extern    int    tgetent();
  129. extern    char    *getenv();
  130. extern    void    new_stty();
  131.  
  132. static    int    term_CE_clear_to_eol();
  133. static    int    term_CS_scroll();
  134. static    int    term_ALDL_scroll();
  135. static    int    term_param_ALDL_scroll();
  136. static    int    term_IC_insert();
  137. static    int    term_IMEI_insert();
  138. static    int    term_DC_delete();
  139. static    int    term_null_function();
  140. static    int    term_BS_cursor_left();
  141. static    int    term_LE_cursor_left();
  142. static    int    term_ND_cursor_right();
  143. #endif /* STTY_ONLY */
  144.  
  145. static    int    tty_des;        /* descriptor for the tty */
  146.  
  147. #ifndef USE_TERMIO
  148. static    struct    ltchars    oldltchars,
  149.             newltchars = { -1, -1, -1, -1, -1, -1};
  150. static    struct    tchars    oldtchars,
  151.             newtchars = { '\003', -1, -1, -1, -1, -1};
  152. static    struct    sgttyb    oldb,
  153.             newb;
  154. #else
  155. static    struct    termio    oldb,
  156.             newb;
  157. #endif /* USE_TERMIO */
  158.  
  159. #ifndef STTY_ONLY
  160.  
  161. static    char    termcap[1024];
  162.  
  163. /*
  164.  * Function variables: each returns 1 if the function is not supported on the
  165.  * current term type, otherwise they do their thing and return 0 
  166.  */
  167. int    (*term_scroll) ();    /* this is set to the best scroll available */
  168. int    (*term_insert) ();    /* this is set to the best insert available */
  169. int    (*term_delete) ();    /* this is set to the best delete available */
  170. int    (*term_cursor_left) ();    /* this is set to the best left available */
  171. int    (*term_cursor_right) ();/* this is set to the best right available */
  172. int    (*term_clear_to_eol) ();/* this is set... figure it out */
  173.  
  174. /* The termcap variables */
  175. char    *CM,
  176.     *CE,
  177.     *CL,
  178.     *CR,
  179.     *NL,
  180.     *AL,
  181.     *DL,
  182.     *CS,
  183.     *DC,
  184.     *IC,
  185.     *IM,
  186.     *EI,
  187.     *SO,
  188.     *SE,
  189.     *US,
  190.     *UE,
  191.     *MD,
  192.     *ME,
  193.     *SF,
  194.     *SR,
  195.     *ND,
  196.     *LE,
  197.     *BL;
  198. int    CO = 79,
  199.     LI = 24,
  200.     SG;
  201.  
  202. /*
  203.  * term_reset_flag: set to true whenever the terminal is reset, thus letter
  204.  * the calling program work out what to do 
  205.  */
  206. int    term_reset_flag = 0;
  207.  
  208. static    int    term_echo_flag = 1;
  209.  
  210. static    int    li,
  211.         co;
  212.  
  213. #endif /* STTY_ONLY */
  214. #ifdef TIOCLSET
  215. static    int    old_local_modes,
  216.         new_local_modes;
  217. #endif
  218.  
  219. #ifndef STTY_ONLY
  220. void
  221. term_intr(c)
  222.     char    c;
  223. {
  224. #if defined(TIOCSETC) && !defined(USE_TERMIO)
  225.     newtchars.t_intrc = c;
  226.     ioctl(tty_des, TIOCSETC, &newtchars);
  227. #endif /* TIOCSETC */
  228. }
  229.  
  230. void
  231. term_susp(c)
  232.     char    c;
  233. {
  234. #ifndef USE_TERMIO
  235.     newltchars.t_suspc = c;
  236.     ioctl(tty_des, TIOCSLTC, &newltchars);
  237. #endif /* USE_TERMIO */
  238. }
  239.  
  240. /*
  241.  * term_echo: if 0, echo is turned off (all characters appear as blanks), if
  242.  * non-zero, all is normal.  The function returns the old value of the
  243.  * term_echo_flag 
  244.  */
  245. int
  246. term_echo(flag)
  247.     int    flag;
  248. {
  249.     int    echo;
  250.  
  251.     echo = term_echo_flag;
  252.     term_echo_flag = flag;
  253.     return (echo);
  254. }
  255.  
  256. /*
  257.  * term_putchar: puts a character to the screen, and displays control
  258.  * characters as inverse video uppercase letters.  NOTE:  Dont use this to
  259.  * display termcap control sequences!  It won't work! 
  260.  */
  261. void
  262. term_putchar(c)
  263.     unsigned char    c;
  264. {
  265.     if (term_echo_flag)
  266.     {
  267.         if (translation)
  268.             c = transToClient[c];
  269.         if (c < 32)
  270.         {
  271.             term_standout_on();
  272.             c = (c & 127) | 64;
  273.             fputc(c, (current_screen?current_screen->fpout:stdout));
  274.             term_standout_off();
  275.         }
  276.         else if (c == '\177')
  277.         {
  278.             term_standout_on();
  279.             c = '?';
  280.             fputc(c, (current_screen?current_screen->fpout:stdout));
  281.             term_standout_off();
  282.         }
  283.         else
  284.             fputc(c, (current_screen?current_screen->fpout:stdout));
  285.     }
  286.     else
  287.     {
  288.         c = ' ';
  289.         fputc(c, (current_screen?current_screen->fpout:stdout));
  290.     }
  291. }
  292.  
  293. /* term_puts: uses term_putchar to print text */
  294. int
  295. term_puts(str, len)
  296.     char    *str;
  297.     int    len;
  298. {
  299.     int    i;
  300.  
  301.     for (i = 0; *str && (i < len); str++, i++)
  302.         term_putchar(*str);
  303.     return (i);
  304. }
  305.  
  306. /* putchar_x: the putchar function used by tputs */
  307. void
  308. putchar_x(c)
  309.     char    c;
  310. {
  311.     fputc(c, (current_screen?current_screen->fpout:stdout));
  312. }
  313.  
  314. void
  315. term_flush()
  316. {
  317.     fflush((current_screen?current_screen->fpout:stdout));
  318. }
  319.  
  320. /*
  321.  * term_reset: sets terminal attributed back to what they were before the
  322.  * program started 
  323.  */
  324. void
  325. term_reset()
  326. {
  327. #ifndef USE_TERMIO
  328.     ioctl(tty_des, TIOCSLTC, &oldltchars);
  329.     ioctl(tty_des, TIOCSETC, &oldtchars);
  330.     ioctl(tty_des, TIOCSETP, &oldb);
  331. #else
  332. # ifdef TCSETA
  333.     ioctl(tty_des, TCSETA, &oldb);
  334. # else
  335.     tcsetattr(tty_des, TCSADRAIN, &oldb);
  336. # endif /* TCSETA */
  337. #endif /* USE_TERMIO */
  338.  
  339. #if (defined(mips) && !defined(ultrix)) || defined(ISC22) || defined(_HPUX_SOURCE)
  340.     new_stty("cooked");
  341. #endif /* mips */
  342.  
  343. #ifdef TIOCLSET
  344.     ioctl(tty_des, TIOCLSET, &old_local_modes);
  345. #endif
  346.     if   (CS)
  347.         tputs_x(tgoto(CS, LI - 1, 0));
  348.     term_move_cursor(0, LI - 1);
  349.     term_reset_flag = 1;
  350.     term_flush();
  351. }
  352.  
  353. /*
  354.  * term_cont: sets the terminal back to IRCII stuff when it is restarted
  355.  * after a SIGSTOP.  Somewhere, this must be used in a signal() call 
  356.  */
  357. RETSIGTYPE
  358. term_cont()
  359. {
  360. #ifdef SYSVSIGNALS
  361.     (void) MY_SIGNAL(SIGCONT, term_cont, 0);    /* sysv has dumb signals */
  362. #endif /* SYSVSIGNALS */
  363.  
  364. #if defined(SIGSTOP) && defined(SIGTSTP)    /* munix doesn't have sigstop sigtstp */
  365. # ifdef USE_TERMIO
  366. #  ifdef TCSETA
  367.     ioctl(tty_des, TCSETA, &newb);
  368. #  else
  369.     tcsetattr(tty_des, TCSADRAIN, &newb);
  370. #  endif /* TCSETA */
  371. # else
  372.     ioctl(tty_des, TIOCSLTC, &newltchars);
  373.     ioctl(tty_des, TIOCSETC, &newtchars);
  374.     ioctl(tty_des, TIOCSETP, &newb);
  375. # endif /* USE_TERMIO */
  376. # if defined(_HPUX_SOURCE) || defined(ISC22)
  377.     new_stty("opost");
  378. # endif /* HPUX || ISC22 */
  379. # if defined(mips) && !defined(ultrix) /*ultrix/mips silliness*/
  380.     new_stty("raw -echo");
  381. # endif /* mips */
  382. #endif /* SIGSTOP && SIGTSTP */
  383.  
  384. #ifdef TIOCLSET
  385.     ioctl(tty_des, TIOCLSET, &new_local_modes);
  386. #endif
  387. }
  388.  
  389. /*
  390.  * term_pause: sets terminal back to pre-program days, then SIGSTOPs itself. 
  391.  */
  392. void
  393. term_pause()
  394. {
  395. #if !defined(SIGSTOP) || !defined(SIGTSTP) || defined(_RT) || defined(ESIX)
  396.     say("The STOP_IRC function does not work on this system type.");
  397. #else
  398.     term_reset();
  399.     kill(getpid(), SIGSTOP);
  400. #endif /* MUNIX */
  401. }
  402. #endif /* STTY_ONLY */
  403.  
  404. /*
  405.  * term_init: does all terminal initialization... reads termcap info, sets
  406.  * the terminal to CBREAK, no ECHO mode.   Chooses the best of the terminal
  407.  * attributes to use ..  for the version of this function that is called for
  408.  * wserv, we set the termial to RAW, no ECHO, so that all the signals are
  409.  * ignored.. fixes quite a few problems...  -phone, jan 1993..
  410.  */
  411. void
  412. term_init()
  413. {
  414. #ifndef    STTY_ONLY
  415.     char    bp[1024],
  416.         *term,
  417.         *ptr;
  418.  
  419.     if ((term = getenv("TERM")) == (char *) 0)
  420.     {
  421.         fprintf(stderr, "irc: No TERM variable set!\n");
  422.         fprintf(stderr,"irc: You may still run irc by using the -d switch\n");
  423.         exit(1);
  424.     }
  425.     if (tgetent(bp, term) < 1)
  426.     {
  427.         fprintf(stderr, "irc: No termcap entry for %s.\n", term);
  428.         fprintf(stderr,"irc: You may still run irc by using the -d switch\n");
  429.         exit(1);
  430.     }
  431. #endif
  432.     if (getenv("IRC_DEBUG")|| (tty_des = open("/dev/tty", O_RDWR, 0)) == -1)
  433.         tty_des = 0;
  434.  
  435. #ifndef USE_TERMIO
  436.     ioctl(tty_des, TIOCGLTC, &oldltchars);
  437.     ioctl(tty_des, TIOCGETC, &oldtchars);
  438.     ioctl(tty_des, TIOCGETP, &oldb);
  439.  
  440.     newb = oldb;
  441.     newb.sg_flags &= ~CRMOD;
  442.  
  443. # ifdef TIOCLSET
  444.     ioctl(tty_des, TIOCLGET, &old_local_modes);
  445.     new_local_modes = old_local_modes | LDECCTQ | LLITOUT | LNOFLSH;
  446.     ioctl(tty_des, TIOCLSET, &new_local_modes);
  447. # endif
  448.  
  449. # ifndef STTY_ONLY
  450.     if (use_flow_control)
  451.     {
  452.         newtchars.t_startc = oldtchars.t_startc;
  453.         newtchars.t_stopc = oldtchars.t_stopc;
  454.     }
  455.     newb.sg_flags |= CBREAK;
  456. # else
  457.     newb.sg_flags |= RAW;
  458. # endif /* STTY_ONLY */
  459.  
  460. # if !defined(_HPUX_SOURCE)
  461.     newb.sg_flags &= (~ECHO);
  462. # endif /* _HPUX_SOURCE */
  463.  
  464.     ioctl(tty_des, TIOCSLTC, &newltchars);
  465.     ioctl(tty_des, TIOCSETC, &newtchars);
  466.     ioctl(tty_des, TIOCSETP, &newb);
  467.  
  468. #else /* USE_TERMIO */
  469.  
  470. # ifdef TCGETA
  471.     ioctl(tty_des, TCGETA, &oldb);
  472. # else
  473.     tcgetattr(tty_des, &oldb);
  474. # endif
  475.     newb = oldb;
  476.     newb.c_lflag &= ~(ICANON | ECHO);    /* set equivalent of
  477.                          * CBREAK and * no
  478.                          * ECHO */
  479.     newb.c_cc[VMIN] = 1;    /* read() satified after 1 char */
  480.     newb.c_cc[VTIME] = 0;    /* No timer */
  481. #ifndef _POSIX_VDISABLE
  482. # define _POSIX_VDISABLE 0
  483. #endif
  484.  
  485.     newb.c_cc[VQUIT] = _POSIX_VDISABLE;
  486. # ifdef VDSUSP
  487.     newb.c_cc[VDSUSP] = _POSIX_VDISABLE;
  488. # endif
  489. # ifdef VSUSP
  490.     newb.c_cc[VSUSP] = _POSIX_VDISABLE;
  491. # endif
  492.  
  493. # ifndef STTY_ONLY
  494.     if (!use_flow_control)
  495.         newb.c_iflag &= ~IXON;    /* No XON/XOFF */
  496. # endif /* STTY_ONLY */
  497.  
  498. # ifdef TCSETA
  499.     ioctl(tty_des, TCSETA, &newb);
  500. # else
  501.     tcsetattr(tty_des, TCSADRAIN, &newb);
  502. # endif
  503.  
  504. #endif /* USE_TERMIO */
  505.  
  506. #ifndef STTY_ONLY
  507. #if defined(mips) && !defined(ultrix)
  508.     new_stty("raw -echo");
  509. #endif /* mips */
  510. #endif /* STTY_ONLY */
  511.  
  512. #ifndef STTY_ONLY
  513.     if ((co = tgetnum("co")) == -1)
  514.         co = 80;
  515.     if ((li = tgetnum("li")) == -1)
  516.         li = 24;
  517.     ptr = termcap;
  518.  
  519.     /*
  520.      * Thanks to Max Bell (mbell@cie.uoregon.edu) for info about TVI
  521.      * terminals and the sg terminal capability 
  522.      */
  523.     SG = tgetnum("sg");
  524.     CM = tgetstr("cm", &ptr);
  525.     CL = tgetstr("cl", &ptr);
  526.     if ((CM == (char *) 0) ||
  527.         (CL == (char *) 0))
  528.     {
  529.         fprintf(stderr, "This terminal does not have the necessary capabilities to run IRCII\nin full screen mode. You may still run irc by using the -d switch\n");
  530.         exit(1);
  531.     }
  532.     if ((CR = tgetstr("cr", &ptr)) == (char *) 0)
  533.         CR = "\r";
  534.     if ((NL = tgetstr("nl", &ptr)) == (char *) 0)
  535.         NL = "\n";
  536.  
  537.     if ((CE = tgetstr("ce", &ptr)) != NULL)
  538.         term_clear_to_eol = term_CE_clear_to_eol;
  539.     else
  540.         term_clear_to_eol = term_null_function;
  541.  
  542.  
  543.     /* if ((ND = tgetstr("nd", &ptr)) || (ND = tgetstr("kr", &ptr))) */
  544.     if ((ND = tgetstr("nd", &ptr)) != NULL)
  545.         term_cursor_right = term_ND_cursor_right;
  546.     else
  547.         term_cursor_right = term_null_function;
  548.  
  549.     /* if ((LE = tgetstr("le", &ptr)) || (LE = tgetstr("kl", &ptr))) */
  550.     if ((LE = tgetstr("le", &ptr)) != NULL)
  551.         term_cursor_left = term_LE_cursor_left;
  552.     else if (tgetflag("bs"))
  553.         term_cursor_left = term_BS_cursor_left;
  554.     else
  555.         term_cursor_left = term_null_function;
  556.  
  557.     SF = tgetstr("sf", &ptr);
  558.     SR = tgetstr("sr", &ptr);
  559.  
  560.     if ((CS = tgetstr("cs", &ptr)) != NULL)
  561.         term_scroll = term_CS_scroll;
  562.     else if ((AL = tgetstr("AL", &ptr)) && (DL = tgetstr("DL", &ptr)))
  563.         term_scroll = term_param_ALDL_scroll;
  564.     else if ((AL = tgetstr("al", &ptr)) && (DL = tgetstr("dl", &ptr)))
  565.         term_scroll = term_ALDL_scroll;
  566.     else
  567.         term_scroll = term_null_function;
  568.  
  569.     if ((IC = tgetstr("ic", &ptr)) != NULL)
  570.         term_insert = term_IC_insert;
  571.     else
  572.     {
  573.         if ((IM = tgetstr("im", &ptr)) && (EI = tgetstr("ei", &ptr)))
  574.             term_insert = term_IMEI_insert;
  575.         else
  576.             term_insert = term_null_function;
  577.     }
  578.  
  579.     if ((DC = tgetstr("dc", &ptr)) != NULL)
  580.         term_delete = term_DC_delete;
  581.     else
  582.         term_delete = term_null_function;
  583.  
  584.     SO = tgetstr("so", &ptr);
  585.     SE = tgetstr("se", &ptr);
  586.     if ((SO == (char *) 0) || (SE == (char *) 0))
  587.     {
  588.         SO = empty_string;
  589.         SE = empty_string;
  590.     }
  591.     US = tgetstr("us", &ptr);
  592.     UE = tgetstr("ue", &ptr);
  593.     if ((US == (char *) 0) || (UE == (char *) 0))
  594.     {
  595.         US = empty_string;
  596.         UE = empty_string;
  597.     }
  598.     MD = tgetstr("md", &ptr);
  599.     ME = tgetstr("me", &ptr);
  600.     if ((MD == (char *) 0) || (ME == (char *) 0))
  601.     {
  602.         MD = empty_string;
  603.         ME = empty_string;
  604.     }
  605.     if ((BL = tgetstr("bl", &ptr)) == (char *) 0)
  606.         BL = "\007";
  607. #endif /* STTY_ONLY */
  608. }
  609.  
  610. #ifndef STTY_ONLY
  611. /*
  612.  * term_resize: gets the terminal height and width.  Trys to get the info
  613.  * from the tty driver about size, if it can't... uses the termcap values. If
  614.  * the terminal size has changed since last time term_resize() has been
  615.  * called, 1 is returned.  If it is unchanged, 0 is returned. 
  616.  */
  617. int
  618. term_resize()
  619. {
  620.     static    int    old_li = -1,
  621.             old_co = -1;
  622.  
  623. #ifndef TIOCGWINSZ
  624.  
  625.     LI = li;
  626.     CO = co;
  627.  
  628. #else
  629.     struct    winsize window;
  630.  
  631.     if (ioctl(tty_des, TIOCGWINSZ, &window) < 0)
  632.     {
  633.         LI = li;
  634.         CO = co;
  635.     }
  636.     else
  637.     {
  638.         if ((LI = window.ws_row) == 0)
  639.             LI = li;
  640.         if ((CO = window.ws_col) == 0)
  641.             CO = co;
  642.     }
  643. #endif /* TIOCGWINSZ */
  644.     CO--;
  645.     if ((old_li != LI) || (old_co != CO))
  646.     {
  647.         old_li = LI;
  648.         old_co = CO;
  649.         return (1);
  650.     }
  651.     return (0);
  652. }
  653.  
  654. /*
  655.  * term_null_function: used when a terminal is missing a particulary useful
  656.  * feature, such as scrolling, to warn the calling program that no such
  657.  * function exists 
  658.  */
  659. static    int
  660. term_null_function()
  661. {
  662.     return (1);
  663. }
  664.  
  665. /* term_CE_clear_to_eol(): the clear to eol function, right? */
  666. static    int
  667. term_CE_clear_to_eol()
  668. {
  669.     tputs_x(CE);
  670.     return (0);
  671. }
  672.  
  673. /* * term_space_erase: this can be used if term_CE_clear_to_eol() returns 1.
  674.  * This will erase from x to the end of the screen uses space.  Actually, it
  675.  * doesn't reposition the cursor at all, so the cursor must be in the correct
  676.  * spot at the beginning and you must move it back afterwards 
  677.  */
  678. void
  679. term_space_erase(x)
  680.     int    x;
  681. {
  682.     char    c = ' ';
  683.     int    i,
  684.         cnt;
  685.  
  686.     cnt = CO - x;
  687.     for (i = 0; i < cnt; i++)
  688.         fputc(c, (current_screen?current_screen->fpout:stdout));
  689. }
  690.  
  691. /*
  692.  * term_CS_scroll: should be used if the terminal has the CS capability by
  693.  * setting term_scroll equal to it 
  694.  */
  695. static    int
  696. term_CS_scroll(line1, line2, n)
  697.     int    line1,
  698.         line2,
  699.         n;
  700. {
  701.     int    i;
  702.     char    *thing;
  703.  
  704.     if (n > 0)
  705.         thing = SF ? SF : NL;
  706.     else if (n < 0)
  707.     {
  708.         if (SR)
  709.             thing = SR;
  710.         else
  711.             return 1;
  712.     }
  713.     else
  714.         return 0;
  715.     tputs_x(tgoto(CS, line2, line1));  /* shouldn't do this each time */
  716.     if (n < 0)
  717.     {
  718.         term_move_cursor(0, line1);
  719.         n = -n;
  720.     }
  721.     else
  722.         term_move_cursor(0, line2);
  723.     for (i = 0; i < n; i++)
  724.         tputs_x(thing);
  725.     tputs_x(tgoto(CS, LI - 1, 0));    /* shouldn't do this each time */
  726.     return (0);
  727. }
  728.  
  729. /*
  730.  * term_ALDL_scroll: should be used for scrolling if the term has AL and DL
  731.  * by setting the term_scroll function to it 
  732.  */
  733. static    int
  734. term_ALDL_scroll(line1, line2, n)
  735.     int    line1,
  736.         line2,
  737.         n;
  738. {
  739.     int    i;
  740.  
  741.     if (n > 0)
  742.     {
  743.         term_move_cursor(0, line1);
  744.         for (i = 0; i < n; i++)
  745.             tputs_x(DL);
  746.         term_move_cursor(0, line2 - n + 1);
  747.         for (i = 0; i < n; i++)
  748.             tputs_x(AL);
  749.     }
  750.     else if (n < 0)
  751.     {
  752.         n = -n;
  753.         term_move_cursor(0, line2-n+1);
  754.         for (i=0; i < n; i++)
  755.             tputs_x(DL);
  756.         term_move_cursor(0, line1);
  757.         for (i=0; i < n; i++)
  758.             tputs_x(AL);
  759.     }
  760.     return (0);
  761. }
  762.  
  763. /*
  764.  * term_param_ALDL_scroll: Uses the parameterized version of AL and DL 
  765.  */
  766. static    int
  767. term_param_ALDL_scroll(line1, line2, n)
  768.     int    line1,
  769.         line2,
  770.         n;
  771. {
  772.     if (n > 0)
  773.     {
  774.         term_move_cursor(0, line1);
  775.         tputs_x(tgoto(DL, n, n));
  776.         term_move_cursor(0, line2 - n + 1);
  777.         tputs_x(tgoto(AL, n, n));
  778.     }
  779.     else if (n < 0)
  780.     {
  781.         n = -n;
  782.         term_move_cursor(0, line2-n+1);
  783.         tputs_x(tgoto(DL, n, n));
  784.         term_move_cursor(0, line1);
  785.         tputs_x(tgoto(AL, n, n));
  786.     }
  787.     return (0);
  788. }
  789.  
  790. /*
  791.  * term_IC_insert: should be used for character inserts if the term has IC by
  792.  * setting term_insert to it. 
  793.  */
  794. static    int
  795. term_IC_insert(c)
  796.     char    c;
  797. {
  798.     tputs_x(IC);
  799.     term_putchar(c);
  800.     return (0);
  801. }
  802.  
  803. /*
  804.  * term_IMEI_insert: should be used for character inserts if the term has IM
  805.  * and EI by setting term_insert to it 
  806.  */
  807. static    int
  808. term_IMEI_insert(c)
  809.     char    c;
  810. {
  811.     tputs_x(IM);
  812.     term_putchar(c);
  813.     tputs_x(EI);
  814.     return (0);
  815. }
  816.  
  817. /*
  818.  * term_DC_delete: should be used for character deletes if the term has DC by
  819.  * setting term_delete to it 
  820.  */
  821. static    int
  822. term_DC_delete()
  823. {
  824.     tputs_x(DC);
  825.     return (0);
  826. }
  827.  
  828. /* term_ND_cursor_right: got it yet? */
  829. static    int
  830. term_ND_cursor_right()
  831. {
  832.     tputs_x(ND);
  833.     return (0);
  834. }
  835.  
  836. /* term_LE_cursor_left:  shouldn't you move on to something else? */
  837. static    int
  838. term_LE_cursor_left()
  839. {
  840.     tputs_x(LE);
  841.     return (0);
  842. }
  843.  
  844. static    int
  845. term_BS_cursor_left()
  846. {
  847.     char    c = '\010';
  848.  
  849.     fputc(c, (current_screen ? current_screen->fpout : stdout));
  850.     return (0);
  851. }
  852.  
  853. extern    void
  854. copy_window_size(lines, columns)
  855.     int    *lines,
  856.         *columns;
  857. {
  858.     *lines = li;
  859.     *columns = co;
  860. }
  861.  
  862. extern    int
  863. term_eight_bit()
  864. {
  865. #if defined(USE_TERMIO)
  866.     return (((oldb.c_cflag) & CSIZE) == CS8) ? 1 : 0;
  867. #else
  868.     return (old_local_modes & LPASS8) ? 1 : 0;
  869. #endif /* USE_TERMIO */
  870. }
  871. #endif /* STTY_ONLY */
  872.  
  873. extern    void
  874. set_term_eight_bit(value)
  875.     int    value;
  876. {
  877. #if defined(USE_TERMIO)
  878.     /*
  879.      * XXX - maybe this should be ISTRIP as well??
  880.      */
  881.     if (value == ON)
  882.         newb.c_cflag |= CS8;
  883.     else
  884.         newb.c_cflag &= ~CS8;
  885. # ifdef TCSETA
  886.     ioctl(tty_des, TCSETA, &newb);
  887. # else
  888.     tcsetattr(tty_des, TCSADRAIN, &newb);
  889. # endif /* TCSETA */
  890. #else
  891.     if (value == ON)
  892.         new_local_modes |= LPASS8;
  893.     else
  894.         new_local_modes &= ~LPASS8;
  895.     ioctl(tty_des, TIOCLSET, &new_local_modes);
  896. #endif /* USE_TERMIO */
  897. }
  898.